/*0sv6NJsBl1XywJ+fpMKzpQQ0qSvrdIQatKioOfCJ8wRenkDf0o+OoAB60KDYgUrE*/
/*
 * @Descripttion: 渲染
 * @version:
 * @Author: Chendch
 * @Date: 2020-10-14 11:11:05
 * @LastEditors: Chendch
 * @LastEditTime: 2021-09-15 10:23:33
 */
import React, {Component, Fragment} from "react";
import {dataSource} from "./../CONSTANCE";
import { ajax, base, cacheTools, high, output, print, promptBox, toast } from 'nc-lightapp-front';
// import Transfer from '../../../Transfer';
import Transfer from '../../../../../uap/public/excomponents/Transfer';
import AttachmentMng from '../../component/AttachmentMng'; //附件管理
import AssignStepDialog from '../../assign/AssignStepDialog'; //向导分配
import BatchUpdateWarzid from '../../batchedit/BatchUpdateWarzidPage'; //重构后的向导批改
import DeleteDialogWapper from '../../component/DeleteDialogWapper';
import DialogWapper from '../../component/DialogWapper';
import ExcelOutput from 'uap/common/components/ExcelOutput';
import { getDialogConfig ,querySupplierVersion} from '../../utils/SupplierUtils';

const {PrintOutput} = high;
const {NCCheckbox,NCPopconfirm,NCDiv, NCRadio} = base;
export default function draw() {
    const {table,button ,search,BillHeadInfo, ncmodal, form, editTable} = this.props;
    const {createBillHeadInfo} = BillHeadInfo; //新加 返回图标和按钮
    const { NCCreateSearch } = search;
    const { createSimpleTable } = table;
    const {createModal} = ncmodal;
    let { createButtonApp} = button;
    const {createForm} = form;
    const {createEditTable} = editTable;
    let title = this.props.nodeType == 'GLOBE_NODE'?this.Lang['10140SUG-000186']:(this.props.nodeType=='GROUP_NODE'?this.Lang['10140SUG-000187']:this.Lang['10140SUG-000188']);
    return (
        this.state.table && <Fragment>
            <div className="nc-single-table uapbd-supplier-main">
                <NCDiv areaCode={NCDiv.config.HEADER} className="nc-singleTable-header-area">
                    <div className="header-title-search-area">
                        {createBillHeadInfo({title:title,initShowBackBtn:false})}
                        <div className="title-search-detail">
                            <span className='showOff'>
                                <NCCheckbox {...this.state.table.showOff}>{this.state.table.showOff.name}</NCCheckbox>
                            </span>
                        </div>
                    </div>
                    <div className="header-button-area">
                        {createButtonApp(this.state.table.buttonConfig)}
                    </div>
                </NCDiv>
                <div className="nc-singleTable-search-area">
                    {NCCreateSearch(this.state.table.search.id, this.state.table.search)}
                </div>
                <div className="nc-singleTable-table-area">
                    {createSimpleTable(this.state.table.mainTable.id, Object.assign({}, this.state.table.mainTable, {
                        dataSource,
                        pkname: "pk_supplier"
                    }))}
                </div>
            </div>
            {createModal('SubjectOrgModal', {
                    color: 'success', // 值： "success"/"info"/"warning"/"danger"
                    title:this.Lang['10140SUG-000256'],// '分配组织'
                    zIndex: 100000,
                    content: orgModal.call(this),
                    leftBtnName:this.Lang['beSureBtnName-001'] , //左侧按钮名称  '确定'
                    rightBtnName:this.Lang['cancelBtnName-001'] , //右侧按钮名称    '取消'
                    hasCloseBtn: false,//控制“X”按钮，显示true，不显示false，默认不显示
                    beSureBtnClick: () => {
                        let data = {
                            "treeData": this.state.rightTree,
                            "phone": this.state.curPhone,
                            "type": 1
                        }
                        ajax({
                            url: '/nccloud/baseapp/mobile/assignorg.do',
                            data: data,
                            success: (res) => {
                                console.log(res);
                            },
                            error: (msg) => {
                                toast({ content: msg.message, color: 'danger' });
                            }
                        });
                    },
                })}
                {createModal('modal')}

                {createModal('createVersion', {//版本化
                    color:'success', // 值： "success"/"info"/"warning"/"danger"
                    title:this.Lang['10140SUG-000252'],//版本化
                    content: <div>
                        {createForm("versionList_card", {})}
                        {createEditTable("versionList", {
                            onRowDoubleClick: onVerDoubleClick.bind(this)
                        })}
                    </div>,
                    leftBtnName:this.Lang['10140SUG-000253'], //创建新版本
                    rightBtnName:this.Lang['10140SUG-000254'], //关闭
                    hasCloseBtn:false,//控制“X”按钮，显示true，不显示false，默认不显示
                    userControl: true,
                    cancelBtnClick:()=>{
                        this.props.modal.close('createVersion');
                    },
                    beSureBtnClick: this.canCreateVersion,
                })}
                {/* 版本化卡片 */}
                {createModal('versionCardmodal', {
                    className: "versionCardmodal",
                    title:this.Lang['10140SUG-000255'],//'版本化卡片'
                    zIndex: 20002,
                    content: <div>
                        {createForm("versionCard", {})}
                    </div>
                })}


                <AttachmentMng  {...{Lang:this.Lang}} ref={(Attachment)=>{this.Attachment=Attachment;}}/>
                {/* 向导批改 */}
                {this.state.batchUpdateStepClick && <BatchUpdateWarzid ref={(BatchUpdateWarzid)=>{this.BatchUpdateWarzid=BatchUpdateWarzid}} {...Object.assign(this.props,{envParam:this.state.envParam,Lang:this.Lang},{listener:{onBeforeSureClick:(callback)=>{callback && callback();let me = this;me.state.openCard?me.initPageData(me.setCardValue,me.setCardStatus): me.onSearch({checagepage:true},me.setTableData)}}})}/>}
                 {/* 向导分配 */}
                {this.state.assignStepClick && <AssignStepDialog {...Object.assign(this.props,{envParam:this.state.envParam,Lang:this.Lang})} ref={(AssignStepDialog)=>{this.AssignStepDialog=AssignStepDialog;}}/>}

                {ReactDOM.createPortal(this.state.openDialog?<DialogWapper Lang={this.Lang} ref={(Dialog)=>{this.Dialog=Dialog;}}/>:null,document.body)}
                {/* 删除Dialog*/}
                {this.state.openDeleteDialog && ReactDOM.createPortal(<DeleteDialogWapper {...Object.assign(getDialogConfig.call(this,'DeleteDialog'),{Lang:this.Lang})} ref={(DeleteDialog)=>{this.DeleteDialog=DeleteDialog;}}/>,document.body)}
                 {/* 打印输出 */}
                {drawOutputComp.call(this)}
                <ExcelOutput
                    {...Object.assign(this.props)}
                    moduleName = 'uapbd'//模块名
                    moduleId = 'supplierExcel'
                    billType = {this.state.billType}//单据类型
                    selectedPKS = {[]}
                    forceRender={this.state.forceRender}
                    appcode={this.props.appcode}
                    pagecode={"10140SUO_base"}
                />
        </Fragment>
    )
}
// 版本化 表格双击
function onVerDoubleClick(record, index, props){
    props.modal.show('versionCardmodal')
    querySupplierVersion(record, index, props)
}

 /*** 渲染输出组件*/
function drawOutputComp() {
    return(
        <PrintOutput
            ref='printOutput'
            url={this.state.printUrl}
            data={{
                funcode:this.props.appcode,//应用的appcode
                nodekey:this.state.printNodeKey,  //需要与数据库保持一致
                oids: this.state.printPks,//打印的数据主键集合
                outputType: "output"
            }}
        >
        </PrintOutput>
    )
}

/**
 * 供应商联系人分配组织
 * 节点选中方式   10140SUG-000258
 * "10140SUG-000259": "包含所有下级",
    "10140SUG-000260": "仅自己",
 */
function orgModal() {
    return (
    <div>
        <Transfer
            TransferId={'org_transferid'}
            leftTreeData={this.state.leftTree}
            rightTreeData={this.state.rightTree}
            selectType={this.state.selectType}
            title={{ left: this.Lang['10140SUG-000257'], right: this.Lang['10140SUG-000081']}}   //待分配组织\已分配组织
        />

        <div className="nc-theme-common-font-c" style={{ width: '100%', border: '1px solid #eee', margin: '3px 0px' }}>
            <span style={{ padding: '8px' }}>{this.Lang['10140SUG-000258']}</span>
            <NCRadio.NCRadioGroup name="selecttype"
                color="danger" selectedValue={this.state.selectType}
                onChange={this.handleChange.bind(this)}
                style={{ 'text-align': 'center', width: '100%' }}>
                <NCRadio value="onlyChild" >{this.Lang['10140SUG-000259']}</NCRadio>
                <NCRadio value="onlySelf" >{this.Lang['10140SUG-000260']}</NCRadio>
            </NCRadio.NCRadioGroup>
        </div>
    </div>)

}
/*0sv6NJsBl1XywJ+fpMKzpQQ0qSvrdIQatKioOfCJ8wRenkDf0o+OoAB60KDYgUrE*/
